package com.fruit.config;

import com.netflix.loadbalancer.ILoadBalancer;
import com.netflix.loadbalancer.IRule;
import com.netflix.loadbalancer.Server;

import java.util.List;

/**
 * @Description: 自定义负载均衡策略
 * @Author: LJ
 * @Date: 2018/10/31 14:16
 * @version:
 */
public class CustomRule implements IRule {

    private ILoadBalancer loadBalancer;

    /**
     * 自定义规则
     *
     * @param o
     * @return
     */
    @Override
    public Server choose(Object o) {
        List<Server> servers = loadBalancer.getAllServers();
        return servers.get(0);
    }

    @Override
    public void setLoadBalancer(ILoadBalancer iLoadBalancer) {
        this.loadBalancer = iLoadBalancer;
    }

    @Override
    public ILoadBalancer getLoadBalancer() {
        return this.loadBalancer;
    }
}
